/**
 * @program: clms-second
 * @description:
 * @author: mitu_echo
 * @create: 2021-07-24 09:01
 **/

package com.second.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.second.common.pojo.R;
import com.second.system.dao.LoginfoDao;
import com.second.system.pojo.entity.Loginfo;
import com.second.system.pojo.utils.MyAnnotation;
import com.second.system.pojo.vo.ShowLoginfoVO;
import com.second.system.service.LoginfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginfoServiceImpl implements LoginfoService {

    @Autowired
    private LoginfoDao loginfoDao;

    @Override
    @MyAnnotation( title = "日志模块",businessType = 0)
    public R showAllLoginfo(ShowLoginfoVO showLoginfoVO) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (StringUtils.isNotEmpty(showLoginfoVO.getTitle())) {
            queryWrapper.like("title",showLoginfoVO.getTitle());
        }
        if (StringUtils.isNotEmpty(showLoginfoVO.getOperName())) {
            queryWrapper.like("oper_name",showLoginfoVO.getOperName());
        }
        queryWrapper.orderByDesc("oper_time");
        PageHelper.startPage(showLoginfoVO.getPageno(),showLoginfoVO.getPagesize());
        List loginfoList = loginfoDao.selectList(queryWrapper);
        PageInfo pageInfo = new PageInfo(loginfoList);
        return R.success().putListData(loginfoList).putObject(pageInfo);
    }

    @Override
    @MyAnnotation( title = "日志模块",businessType = 3)
    public R deleteLoginfoById(Integer logid) {

        int i = loginfoDao.deleteById(logid);
        if (i>0) {
            return R.success();
        }
        return R.error();
    }

    @Override
    @MyAnnotation( title = "日志模块",businessType = 1)
    public void addLoginfo(Loginfo loginfo) {

        loginfoDao.insert(loginfo);
    }
}
